{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 导入需要的库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "ModuleNotFoundError",
     "evalue": "No module named 'pydantic_settings'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mModuleNotFoundError\u001b[0m                       Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[1], line 11\u001b[0m\n\u001b[0;32m      7\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mjoblib\u001b[39;00m \u001b[38;5;66;03m#导入模型保存模块\u001b[39;00m\n\u001b[0;32m      8\u001b[0m \u001b[38;5;66;03m# 将\u001b[39;00m\n\u001b[0;32m      9\u001b[0m \u001b[38;5;66;03m# from pydantic import BaseSettings\u001b[39;00m\n\u001b[0;32m     10\u001b[0m \u001b[38;5;66;03m# 改为\u001b[39;00m\n\u001b[1;32m---> 11\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mpydantic_settings\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m BaseSettings\n\u001b[0;32m     12\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas_profiling\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mprof\u001b[39;00m \u001b[38;5;66;03m#导入pandas_profiling数据EDA库\u001b[39;00m\n",
      "\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'pydantic_settings'"
     ]
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m在当前单元格或上一个单元格中执行代码时 Kernel 崩溃。\n",
      "\u001b[1;31m请查看单元格中的代码，以确定故障的可能原因。\n",
      "\u001b[1;31m单击<a href='https://aka.ms/vscodeJupyterKernelCrash'>此处</a>了解详细信息。\n",
      "\u001b[1;31m有关更多详细信息，请查看 Jupyter <a href='command:jupyter.viewOutput'>log</a>。"
     ]
    }
   ],
   "source": [
    "import pandas as pd#导入pandas库对数据进行读取\n",
    "import numpy as np #导入numpy\n",
    "from sklearn.preprocessing import LabelEncoder,LabelBinarizer,StandardScaler#导入标签编码器\n",
    "from sklearn.model_selection import train_test_split,GridSearchCV#导入数据划分器\n",
    "from sklearn.linear_model import LogisticRegression#导入逻辑回归模型做分类\n",
    "from sklearn.ensemble import RandomForestClassifier\n",
    "import joblib #导入模型保存模块\n",
    "# 将\n",
    "# from pydantic import BaseSettings\n",
    "# 改为\n",
    "from pydantic_settings import BaseSettings\n",
    "import pandas_profiling as prof #导入pandas_profiling数据EDA库"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据处理函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "metadata": {},
   "outputs": [],
   "source": [
    "def data_clean(file_path):\n",
    "    '''\n",
    "    数据处理函数\n",
    "    parameters：\n",
    "    file_path:数据文件路径 \n",
    "    '''\n",
    "    data=pd.read_csv(file_path)\n",
    "    #删除不需要的列\n",
    "    data.drop('PassengerId',axis=1,inplace=True)\n",
    "    data.drop(['Name','Ticket','Cabin'],axis=1,inplace=True)\n",
    "    #对空值进行填充\n",
    "    data['Age'].fillna(data['Age'].mean(),inplace=True)\n",
    "    #对字符的东西进行一个空值的填充\n",
    "    data['Embarked'].fillna(data['Embarked'].mode()[0],inplace=True)\n",
    "    #数据preprocessing\n",
    "    data['Sex']=LabelBinarizer().fit_transform(data['Sex'])\n",
    "    data=pd.get_dummies(data)\n",
    "    data['Fare']=StandardScaler().fit_transform(data['Fare'].values.reshape(-1,1))\n",
    "\n",
    "    return(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 数据划分函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "metadata": {},
   "outputs": [],
   "source": [
    "def data_split(data):\n",
    "    ''' \n",
    "    数据划分函数\n",
    "    parameters：\n",
    "    data：待划分的数据\n",
    "    '''\n",
    "    x=data.drop('Survived',axis=1)\n",
    "    y=data['Survived']\n",
    "    x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,shuffle=True)\n",
    "\n",
    "    return(x_train,x_test,y_train,y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 网格搜索函数\n",
    "### 可以考虑将模型和参数作为参数传入"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 随机森林网格搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "metadata": {},
   "outputs": [],
   "source": [
    "def model_fit(x,y):\n",
    "    ''' \n",
    "    搜索随机森林模型的最优参数\n",
    "    parameters：\n",
    "    x：特征\n",
    "    y：标签\n",
    "    '''\n",
    "    #定义好参数\n",
    "    Para_grid=[{'n_estimators':[3,10,30,50,100],'max_features':[2,4,6,8]},\n",
    "    {'bootstrap':[False],'n_estimators':[3,10],'max_features':[2,4,6]}]\n",
    "    #模型的实例化\n",
    "    model=RandomForestClassifier()\n",
    "    #网格搜索与交叉验证\n",
    "    grid_search=GridSearchCV(model,Para_grid,cv=5)\n",
    "    #模型训练\n",
    "    grid_search.fit(x,y)\n",
    "\n",
    "    return(grid_search.best_params_,grid_search.best_estimator_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Catboost网格搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def catboost_GridSearch(x,y):\n",
    "    ''' \n",
    "    搜索CatBoostClassifier最优参数\n",
    "    parameters：\n",
    "    x：特征\n",
    "    y：标签\n",
    "    '''\n",
    "    #定义好参数\n",
    "    Para_grid={'iterations':[300,400,500,600,700],'learning_rate':[0.005,0.01,0.03,0.05],\\\n",
    "        'depth':[5,6,7,8]}\n",
    "\n",
    "    #模型的实例化\n",
    "    model=CatBoostClassifier()\n",
    "    #网格搜索与交叉验证\n",
    "    grid_search=GridSearchCV(model,Para_grid,cv=3)\n",
    "    #模型训练\n",
    "    grid_search.fit(x,y)\n",
    "\n",
    "    return(grid_search.best_params_,grid_search.best_estimator_)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 使用自定义函数的处理流程"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=data_clean('data/train.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train,x_test,y_train,y_test=data_split(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [],
   "source": [
    "_,model=model_fit(x_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-21 {color: black;background-color: white;}#sk-container-id-21 pre{padding: 0;}#sk-container-id-21 div.sk-toggleable {background-color: white;}#sk-container-id-21 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-21 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-21 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-21 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-21 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-21 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-21 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-21 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-21 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-21 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-21 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-21 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-21 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-21 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-21 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-21 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-21 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-21 div.sk-item {position: relative;z-index: 1;}#sk-container-id-21 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-21 div.sk-item::before, #sk-container-id-21 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-21 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-21 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-21 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-21 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-21 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-21 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-21 div.sk-label-container {text-align: center;}#sk-container-id-21 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-21 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-21\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestClassifier(max_features=4, n_estimators=50)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-21\" type=\"checkbox\" checked><label for=\"sk-estimator-id-21\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestClassifier</label><div class=\"sk-toggleable__content\"><pre>RandomForestClassifier(max_features=4, n_estimators=50)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "RandomForestClassifier(max_features=4, n_estimators=50)"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>#sk-container-id-22 {color: black;background-color: white;}#sk-container-id-22 pre{padding: 0;}#sk-container-id-22 div.sk-toggleable {background-color: white;}#sk-container-id-22 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-22 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-22 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-22 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-22 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-22 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-22 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-22 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-22 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-22 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-22 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-22 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-22 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-22 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-22 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-22 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-22 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-22 div.sk-item {position: relative;z-index: 1;}#sk-container-id-22 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-22 div.sk-item::before, #sk-container-id-22 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-22 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-22 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-22 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-22 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-22 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-22 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-22 div.sk-label-container {text-align: center;}#sk-container-id-22 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-22 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-22\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>RandomForestClassifier(max_features=4, n_estimators=50)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-22\" type=\"checkbox\" checked><label for=\"sk-estimator-id-22\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestClassifier</label><div class=\"sk-toggleable__content\"><pre>RandomForestClassifier(max_features=4, n_estimators=50)</pre></div></div></div></div></div>"
      ],
      "text/plain": [
       "RandomForestClassifier(max_features=4, n_estimators=50)"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(x_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8156424581005587"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.score(x_test,y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 尝试Xgboost、Lightgbm、Catboost进行模型训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 185,
   "metadata": {},
   "outputs": [],
   "source": [
    "from xgboost import XGBClassifier\n",
    "from lightgbm import LGBMClassifier\n",
    "from catboost import CatBoostClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "catboost_GridSearch(x_train,y_train) #上述定义的catboost超参数来自这里"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "metadata": {},
   "outputs": [],
   "source": [
    "xgb_clf=XGBClassifier()\n",
    "lgb_clf=LGBMClassifier()\n",
    "cat_clf=CatBoostClassifier(**{'depth': 8, 'iterations': 300, 'learning_rate': 0.03})#这里的参数来自于网格搜索"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 196,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0:\tlearn: 0.6726367\ttotal: 2.29ms\tremaining: 684ms\n",
      "1:\tlearn: 0.6546046\ttotal: 3.19ms\tremaining: 475ms\n",
      "2:\tlearn: 0.6378752\ttotal: 5.23ms\tremaining: 518ms\n",
      "3:\tlearn: 0.6212645\ttotal: 7.57ms\tremaining: 560ms\n",
      "4:\tlearn: 0.6049686\ttotal: 9.96ms\tremaining: 588ms\n",
      "5:\tlearn: 0.5920635\ttotal: 12.2ms\tremaining: 599ms\n",
      "6:\tlearn: 0.5778596\ttotal: 14.4ms\tremaining: 604ms\n",
      "7:\tlearn: 0.5684371\ttotal: 15.1ms\tremaining: 550ms\n",
      "8:\tlearn: 0.5560309\ttotal: 17.4ms\tremaining: 563ms\n",
      "9:\tlearn: 0.5450940\ttotal: 19.7ms\tremaining: 572ms\n",
      "10:\tlearn: 0.5341275\ttotal: 22ms\tremaining: 577ms\n",
      "11:\tlearn: 0.5243697\ttotal: 24.6ms\tremaining: 590ms\n",
      "12:\tlearn: 0.5149266\ttotal: 27ms\tremaining: 595ms\n",
      "13:\tlearn: 0.5073611\ttotal: 28ms\tremaining: 572ms\n",
      "14:\tlearn: 0.4991620\ttotal: 30ms\tremaining: 570ms\n",
      "15:\tlearn: 0.4917368\ttotal: 31.4ms\tremaining: 557ms\n",
      "16:\tlearn: 0.4836973\ttotal: 33.5ms\tremaining: 558ms\n",
      "17:\tlearn: 0.4764520\ttotal: 35.6ms\tremaining: 557ms\n",
      "18:\tlearn: 0.4694913\ttotal: 37.8ms\tremaining: 558ms\n",
      "19:\tlearn: 0.4624872\ttotal: 40ms\tremaining: 560ms\n",
      "20:\tlearn: 0.4585428\ttotal: 40.9ms\tremaining: 543ms\n",
      "21:\tlearn: 0.4531977\ttotal: 43ms\tremaining: 544ms\n",
      "22:\tlearn: 0.4490629\ttotal: 45.1ms\tremaining: 543ms\n",
      "23:\tlearn: 0.4433673\ttotal: 47.2ms\tremaining: 543ms\n",
      "24:\tlearn: 0.4381085\ttotal: 49.3ms\tremaining: 542ms\n",
      "25:\tlearn: 0.4339852\ttotal: 51.4ms\tremaining: 542ms\n",
      "26:\tlearn: 0.4294109\ttotal: 53.6ms\tremaining: 542ms\n",
      "27:\tlearn: 0.4251668\ttotal: 55.8ms\tremaining: 542ms\n",
      "28:\tlearn: 0.4208858\ttotal: 58ms\tremaining: 542ms\n",
      "29:\tlearn: 0.4193039\ttotal: 58.7ms\tremaining: 528ms\n",
      "30:\tlearn: 0.4159025\ttotal: 60.8ms\tremaining: 528ms\n",
      "31:\tlearn: 0.4110437\ttotal: 63.1ms\tremaining: 529ms\n",
      "32:\tlearn: 0.4090458\ttotal: 64ms\tremaining: 518ms\n",
      "33:\tlearn: 0.4057067\ttotal: 66.4ms\tremaining: 520ms\n",
      "34:\tlearn: 0.4028294\ttotal: 68.8ms\tremaining: 521ms\n",
      "35:\tlearn: 0.3992925\ttotal: 71.1ms\tremaining: 521ms\n",
      "36:\tlearn: 0.3961843\ttotal: 73.3ms\tremaining: 521ms\n",
      "37:\tlearn: 0.3941823\ttotal: 75.6ms\tremaining: 522ms\n",
      "38:\tlearn: 0.3915554\ttotal: 77.8ms\tremaining: 521ms\n",
      "39:\tlearn: 0.3892962\ttotal: 79.9ms\tremaining: 519ms\n",
      "40:\tlearn: 0.3867395\ttotal: 82.3ms\tremaining: 520ms\n",
      "41:\tlearn: 0.3846465\ttotal: 84.4ms\tremaining: 519ms\n",
      "42:\tlearn: 0.3830605\ttotal: 86.6ms\tremaining: 518ms\n",
      "43:\tlearn: 0.3808959\ttotal: 88.7ms\tremaining: 516ms\n",
      "44:\tlearn: 0.3785204\ttotal: 90.8ms\tremaining: 515ms\n",
      "45:\tlearn: 0.3768644\ttotal: 92.8ms\tremaining: 512ms\n",
      "46:\tlearn: 0.3757370\ttotal: 94.9ms\tremaining: 511ms\n",
      "47:\tlearn: 0.3740044\ttotal: 96.9ms\tremaining: 509ms\n",
      "48:\tlearn: 0.3719369\ttotal: 99ms\tremaining: 507ms\n",
      "49:\tlearn: 0.3697567\ttotal: 101ms\tremaining: 506ms\n",
      "50:\tlearn: 0.3683453\ttotal: 103ms\tremaining: 504ms\n",
      "51:\tlearn: 0.3664445\ttotal: 106ms\tremaining: 503ms\n",
      "52:\tlearn: 0.3646786\ttotal: 108ms\tremaining: 502ms\n",
      "53:\tlearn: 0.3636610\ttotal: 109ms\tremaining: 496ms\n",
      "54:\tlearn: 0.3620893\ttotal: 111ms\tremaining: 494ms\n",
      "55:\tlearn: 0.3605362\ttotal: 113ms\tremaining: 492ms\n",
      "56:\tlearn: 0.3600034\ttotal: 115ms\tremaining: 490ms\n",
      "57:\tlearn: 0.3586900\ttotal: 117ms\tremaining: 489ms\n",
      "58:\tlearn: 0.3572005\ttotal: 120ms\tremaining: 488ms\n",
      "59:\tlearn: 0.3552580\ttotal: 122ms\tremaining: 486ms\n",
      "60:\tlearn: 0.3543510\ttotal: 124ms\tremaining: 485ms\n",
      "61:\tlearn: 0.3535637\ttotal: 126ms\tremaining: 483ms\n",
      "62:\tlearn: 0.3533557\ttotal: 127ms\tremaining: 477ms\n",
      "63:\tlearn: 0.3524874\ttotal: 129ms\tremaining: 475ms\n",
      "64:\tlearn: 0.3513249\ttotal: 131ms\tremaining: 474ms\n",
      "65:\tlearn: 0.3502420\ttotal: 133ms\tremaining: 472ms\n",
      "66:\tlearn: 0.3483216\ttotal: 135ms\tremaining: 471ms\n",
      "67:\tlearn: 0.3476406\ttotal: 137ms\tremaining: 469ms\n",
      "68:\tlearn: 0.3464608\ttotal: 140ms\tremaining: 467ms\n",
      "69:\tlearn: 0.3455191\ttotal: 142ms\tremaining: 466ms\n",
      "70:\tlearn: 0.3445849\ttotal: 144ms\tremaining: 464ms\n",
      "71:\tlearn: 0.3434765\ttotal: 146ms\tremaining: 464ms\n",
      "72:\tlearn: 0.3432684\ttotal: 147ms\tremaining: 458ms\n",
      "73:\tlearn: 0.3417702\ttotal: 150ms\tremaining: 457ms\n",
      "74:\tlearn: 0.3412618\ttotal: 152ms\tremaining: 455ms\n",
      "75:\tlearn: 0.3409314\ttotal: 153ms\tremaining: 450ms\n",
      "76:\tlearn: 0.3398258\ttotal: 155ms\tremaining: 448ms\n",
      "77:\tlearn: 0.3383429\ttotal: 157ms\tremaining: 447ms\n",
      "78:\tlearn: 0.3376810\ttotal: 159ms\tremaining: 445ms\n",
      "79:\tlearn: 0.3369482\ttotal: 161ms\tremaining: 444ms\n",
      "80:\tlearn: 0.3364548\ttotal: 164ms\tremaining: 443ms\n",
      "81:\tlearn: 0.3355250\ttotal: 166ms\tremaining: 441ms\n",
      "82:\tlearn: 0.3345601\ttotal: 168ms\tremaining: 439ms\n",
      "83:\tlearn: 0.3335827\ttotal: 170ms\tremaining: 437ms\n",
      "84:\tlearn: 0.3330119\ttotal: 172ms\tremaining: 436ms\n",
      "85:\tlearn: 0.3321809\ttotal: 174ms\tremaining: 434ms\n",
      "86:\tlearn: 0.3310263\ttotal: 176ms\tremaining: 432ms\n",
      "87:\tlearn: 0.3309200\ttotal: 178ms\tremaining: 428ms\n",
      "88:\tlearn: 0.3307841\ttotal: 180ms\tremaining: 427ms\n",
      "89:\tlearn: 0.3303257\ttotal: 181ms\tremaining: 422ms\n",
      "90:\tlearn: 0.3290101\ttotal: 183ms\tremaining: 420ms\n",
      "91:\tlearn: 0.3278991\ttotal: 185ms\tremaining: 419ms\n",
      "92:\tlearn: 0.3272334\ttotal: 187ms\tremaining: 417ms\n",
      "93:\tlearn: 0.3268585\ttotal: 188ms\tremaining: 413ms\n",
      "94:\tlearn: 0.3267530\ttotal: 189ms\tremaining: 408ms\n",
      "95:\tlearn: 0.3265944\ttotal: 191ms\tremaining: 406ms\n",
      "96:\tlearn: 0.3259031\ttotal: 194ms\tremaining: 405ms\n",
      "97:\tlearn: 0.3256717\ttotal: 196ms\tremaining: 404ms\n",
      "98:\tlearn: 0.3252217\ttotal: 198ms\tremaining: 402ms\n",
      "99:\tlearn: 0.3251019\ttotal: 199ms\tremaining: 398ms\n",
      "100:\tlearn: 0.3244684\ttotal: 201ms\tremaining: 397ms\n",
      "101:\tlearn: 0.3239532\ttotal: 203ms\tremaining: 394ms\n",
      "102:\tlearn: 0.3236264\ttotal: 205ms\tremaining: 392ms\n",
      "103:\tlearn: 0.3228149\ttotal: 207ms\tremaining: 390ms\n",
      "104:\tlearn: 0.3225328\ttotal: 209ms\tremaining: 389ms\n",
      "105:\tlearn: 0.3217340\ttotal: 211ms\tremaining: 387ms\n",
      "106:\tlearn: 0.3209271\ttotal: 214ms\tremaining: 385ms\n",
      "107:\tlearn: 0.3207005\ttotal: 216ms\tremaining: 384ms\n",
      "108:\tlearn: 0.3205290\ttotal: 217ms\tremaining: 380ms\n",
      "109:\tlearn: 0.3194505\ttotal: 219ms\tremaining: 378ms\n",
      "110:\tlearn: 0.3187762\ttotal: 221ms\tremaining: 376ms\n",
      "111:\tlearn: 0.3181268\ttotal: 223ms\tremaining: 374ms\n",
      "112:\tlearn: 0.3177508\ttotal: 225ms\tremaining: 373ms\n",
      "113:\tlearn: 0.3174519\ttotal: 227ms\tremaining: 371ms\n",
      "114:\tlearn: 0.3165362\ttotal: 230ms\tremaining: 369ms\n",
      "115:\tlearn: 0.3163411\ttotal: 231ms\tremaining: 367ms\n",
      "116:\tlearn: 0.3159325\ttotal: 233ms\tremaining: 364ms\n",
      "117:\tlearn: 0.3157130\ttotal: 235ms\tremaining: 362ms\n",
      "118:\tlearn: 0.3151407\ttotal: 237ms\tremaining: 360ms\n",
      "119:\tlearn: 0.3144470\ttotal: 245ms\tremaining: 367ms\n",
      "120:\tlearn: 0.3140199\ttotal: 247ms\tremaining: 365ms\n",
      "121:\tlearn: 0.3128618\ttotal: 249ms\tremaining: 363ms\n",
      "122:\tlearn: 0.3128292\ttotal: 249ms\tremaining: 359ms\n",
      "123:\tlearn: 0.3127613\ttotal: 250ms\tremaining: 355ms\n",
      "124:\tlearn: 0.3123295\ttotal: 251ms\tremaining: 351ms\n",
      "125:\tlearn: 0.3120266\ttotal: 252ms\tremaining: 348ms\n",
      "126:\tlearn: 0.3117766\ttotal: 254ms\tremaining: 346ms\n",
      "127:\tlearn: 0.3117296\ttotal: 255ms\tremaining: 342ms\n",
      "128:\tlearn: 0.3115479\ttotal: 256ms\tremaining: 339ms\n",
      "129:\tlearn: 0.3112369\ttotal: 259ms\tremaining: 338ms\n",
      "130:\tlearn: 0.3104443\ttotal: 261ms\tremaining: 336ms\n",
      "131:\tlearn: 0.3097514\ttotal: 263ms\tremaining: 334ms\n",
      "132:\tlearn: 0.3096852\ttotal: 264ms\tremaining: 331ms\n",
      "133:\tlearn: 0.3095558\ttotal: 264ms\tremaining: 327ms\n",
      "134:\tlearn: 0.3092301\ttotal: 266ms\tremaining: 326ms\n",
      "135:\tlearn: 0.3085914\ttotal: 268ms\tremaining: 323ms\n",
      "136:\tlearn: 0.3078537\ttotal: 270ms\tremaining: 321ms\n",
      "137:\tlearn: 0.3067724\ttotal: 272ms\tremaining: 319ms\n",
      "138:\tlearn: 0.3066148\ttotal: 273ms\tremaining: 316ms\n",
      "139:\tlearn: 0.3064628\ttotal: 274ms\tremaining: 314ms\n",
      "140:\tlearn: 0.3057404\ttotal: 277ms\tremaining: 312ms\n",
      "141:\tlearn: 0.3047911\ttotal: 279ms\tremaining: 310ms\n",
      "142:\tlearn: 0.3045202\ttotal: 281ms\tremaining: 308ms\n",
      "143:\tlearn: 0.3042029\ttotal: 283ms\tremaining: 306ms\n",
      "144:\tlearn: 0.3037305\ttotal: 285ms\tremaining: 304ms\n",
      "145:\tlearn: 0.3031809\ttotal: 287ms\tremaining: 303ms\n",
      "146:\tlearn: 0.3026105\ttotal: 289ms\tremaining: 301ms\n",
      "147:\tlearn: 0.3021762\ttotal: 291ms\tremaining: 299ms\n",
      "148:\tlearn: 0.3018332\ttotal: 293ms\tremaining: 297ms\n",
      "149:\tlearn: 0.3011773\ttotal: 295ms\tremaining: 295ms\n",
      "150:\tlearn: 0.3004758\ttotal: 297ms\tremaining: 293ms\n",
      "151:\tlearn: 0.3002566\ttotal: 299ms\tremaining: 291ms\n",
      "152:\tlearn: 0.2996128\ttotal: 301ms\tremaining: 289ms\n",
      "153:\tlearn: 0.2991400\ttotal: 304ms\tremaining: 288ms\n",
      "154:\tlearn: 0.2987303\ttotal: 306ms\tremaining: 286ms\n",
      "155:\tlearn: 0.2983203\ttotal: 307ms\tremaining: 283ms\n",
      "156:\tlearn: 0.2981311\ttotal: 309ms\tremaining: 282ms\n",
      "157:\tlearn: 0.2978405\ttotal: 311ms\tremaining: 280ms\n",
      "158:\tlearn: 0.2969714\ttotal: 313ms\tremaining: 278ms\n",
      "159:\tlearn: 0.2964195\ttotal: 315ms\tremaining: 276ms\n",
      "160:\tlearn: 0.2963569\ttotal: 316ms\tremaining: 273ms\n",
      "161:\tlearn: 0.2948567\ttotal: 318ms\tremaining: 271ms\n",
      "162:\tlearn: 0.2946256\ttotal: 319ms\tremaining: 268ms\n",
      "163:\tlearn: 0.2942699\ttotal: 321ms\tremaining: 266ms\n",
      "164:\tlearn: 0.2941156\ttotal: 323ms\tremaining: 264ms\n",
      "165:\tlearn: 0.2938878\ttotal: 325ms\tremaining: 262ms\n",
      "166:\tlearn: 0.2933786\ttotal: 327ms\tremaining: 260ms\n",
      "167:\tlearn: 0.2933475\ttotal: 328ms\tremaining: 258ms\n",
      "168:\tlearn: 0.2933195\ttotal: 329ms\tremaining: 255ms\n",
      "169:\tlearn: 0.2923748\ttotal: 331ms\tremaining: 253ms\n",
      "170:\tlearn: 0.2917439\ttotal: 333ms\tremaining: 251ms\n",
      "171:\tlearn: 0.2914664\ttotal: 334ms\tremaining: 248ms\n",
      "172:\tlearn: 0.2914518\ttotal: 334ms\tremaining: 245ms\n",
      "173:\tlearn: 0.2911983\ttotal: 336ms\tremaining: 244ms\n",
      "174:\tlearn: 0.2909726\ttotal: 338ms\tremaining: 241ms\n",
      "175:\tlearn: 0.2904561\ttotal: 340ms\tremaining: 239ms\n",
      "176:\tlearn: 0.2891735\ttotal: 342ms\tremaining: 238ms\n",
      "177:\tlearn: 0.2891430\ttotal: 343ms\tremaining: 235ms\n",
      "178:\tlearn: 0.2884814\ttotal: 345ms\tremaining: 233ms\n",
      "179:\tlearn: 0.2880993\ttotal: 347ms\tremaining: 231ms\n",
      "180:\tlearn: 0.2876807\ttotal: 349ms\tremaining: 230ms\n",
      "181:\tlearn: 0.2867053\ttotal: 351ms\tremaining: 228ms\n",
      "182:\tlearn: 0.2861821\ttotal: 353ms\tremaining: 226ms\n",
      "183:\tlearn: 0.2861566\ttotal: 354ms\tremaining: 223ms\n",
      "184:\tlearn: 0.2858921\ttotal: 356ms\tremaining: 221ms\n",
      "185:\tlearn: 0.2851129\ttotal: 358ms\tremaining: 219ms\n",
      "186:\tlearn: 0.2842849\ttotal: 360ms\tremaining: 217ms\n",
      "187:\tlearn: 0.2835391\ttotal: 362ms\tremaining: 215ms\n",
      "188:\tlearn: 0.2828854\ttotal: 364ms\tremaining: 214ms\n",
      "189:\tlearn: 0.2817794\ttotal: 366ms\tremaining: 212ms\n",
      "190:\tlearn: 0.2810278\ttotal: 368ms\tremaining: 210ms\n",
      "191:\tlearn: 0.2804439\ttotal: 370ms\tremaining: 208ms\n",
      "192:\tlearn: 0.2803007\ttotal: 372ms\tremaining: 206ms\n",
      "193:\tlearn: 0.2797567\ttotal: 374ms\tremaining: 204ms\n",
      "194:\tlearn: 0.2793279\ttotal: 376ms\tremaining: 202ms\n",
      "195:\tlearn: 0.2785699\ttotal: 378ms\tremaining: 200ms\n",
      "196:\tlearn: 0.2780954\ttotal: 380ms\tremaining: 199ms\n",
      "197:\tlearn: 0.2777724\ttotal: 382ms\tremaining: 197ms\n",
      "198:\tlearn: 0.2776049\ttotal: 384ms\tremaining: 195ms\n",
      "199:\tlearn: 0.2765429\ttotal: 386ms\tremaining: 193ms\n",
      "200:\tlearn: 0.2759501\ttotal: 388ms\tremaining: 191ms\n",
      "201:\tlearn: 0.2756871\ttotal: 390ms\tremaining: 189ms\n",
      "202:\tlearn: 0.2755534\ttotal: 392ms\tremaining: 187ms\n",
      "203:\tlearn: 0.2753123\ttotal: 394ms\tremaining: 185ms\n",
      "204:\tlearn: 0.2747522\ttotal: 396ms\tremaining: 184ms\n",
      "205:\tlearn: 0.2742008\ttotal: 398ms\tremaining: 182ms\n",
      "206:\tlearn: 0.2736631\ttotal: 400ms\tremaining: 180ms\n",
      "207:\tlearn: 0.2728881\ttotal: 402ms\tremaining: 178ms\n",
      "208:\tlearn: 0.2721221\ttotal: 404ms\tremaining: 176ms\n",
      "209:\tlearn: 0.2720901\ttotal: 405ms\tremaining: 174ms\n",
      "210:\tlearn: 0.2714513\ttotal: 407ms\tremaining: 172ms\n",
      "211:\tlearn: 0.2708730\ttotal: 409ms\tremaining: 170ms\n",
      "212:\tlearn: 0.2705709\ttotal: 411ms\tremaining: 168ms\n",
      "213:\tlearn: 0.2703196\ttotal: 413ms\tremaining: 166ms\n",
      "214:\tlearn: 0.2696854\ttotal: 415ms\tremaining: 164ms\n",
      "215:\tlearn: 0.2695170\ttotal: 417ms\tremaining: 162ms\n",
      "216:\tlearn: 0.2691493\ttotal: 419ms\tremaining: 160ms\n",
      "217:\tlearn: 0.2686778\ttotal: 421ms\tremaining: 158ms\n",
      "218:\tlearn: 0.2679663\ttotal: 423ms\tremaining: 156ms\n",
      "219:\tlearn: 0.2677695\ttotal: 425ms\tremaining: 155ms\n",
      "220:\tlearn: 0.2674822\ttotal: 427ms\tremaining: 153ms\n",
      "221:\tlearn: 0.2674619\ttotal: 428ms\tremaining: 150ms\n",
      "222:\tlearn: 0.2674469\ttotal: 428ms\tremaining: 148ms\n",
      "223:\tlearn: 0.2672988\ttotal: 430ms\tremaining: 146ms\n",
      "224:\tlearn: 0.2664954\ttotal: 432ms\tremaining: 144ms\n",
      "225:\tlearn: 0.2660216\ttotal: 434ms\tremaining: 142ms\n",
      "226:\tlearn: 0.2657235\ttotal: 436ms\tremaining: 140ms\n",
      "227:\tlearn: 0.2655439\ttotal: 438ms\tremaining: 138ms\n",
      "228:\tlearn: 0.2648714\ttotal: 441ms\tremaining: 137ms\n",
      "229:\tlearn: 0.2645415\ttotal: 443ms\tremaining: 135ms\n",
      "230:\tlearn: 0.2639398\ttotal: 445ms\tremaining: 133ms\n",
      "231:\tlearn: 0.2634339\ttotal: 447ms\tremaining: 131ms\n",
      "232:\tlearn: 0.2630314\ttotal: 449ms\tremaining: 129ms\n",
      "233:\tlearn: 0.2628322\ttotal: 451ms\tremaining: 127ms\n",
      "234:\tlearn: 0.2627105\ttotal: 452ms\tremaining: 125ms\n",
      "235:\tlearn: 0.2625391\ttotal: 454ms\tremaining: 123ms\n",
      "236:\tlearn: 0.2612858\ttotal: 456ms\tremaining: 121ms\n",
      "237:\tlearn: 0.2608190\ttotal: 458ms\tremaining: 119ms\n",
      "238:\tlearn: 0.2598135\ttotal: 460ms\tremaining: 117ms\n",
      "239:\tlearn: 0.2596976\ttotal: 462ms\tremaining: 116ms\n",
      "240:\tlearn: 0.2596386\ttotal: 463ms\tremaining: 113ms\n",
      "241:\tlearn: 0.2590720\ttotal: 465ms\tremaining: 111ms\n",
      "242:\tlearn: 0.2580066\ttotal: 467ms\tremaining: 109ms\n",
      "243:\tlearn: 0.2579420\ttotal: 467ms\tremaining: 107ms\n",
      "244:\tlearn: 0.2574655\ttotal: 469ms\tremaining: 105ms\n",
      "245:\tlearn: 0.2567504\ttotal: 471ms\tremaining: 103ms\n",
      "246:\tlearn: 0.2564839\ttotal: 473ms\tremaining: 102ms\n",
      "247:\tlearn: 0.2563501\ttotal: 475ms\tremaining: 99.7ms\n",
      "248:\tlearn: 0.2558078\ttotal: 477ms\tremaining: 97.7ms\n",
      "249:\tlearn: 0.2556256\ttotal: 479ms\tremaining: 95.9ms\n",
      "250:\tlearn: 0.2547359\ttotal: 481ms\tremaining: 94ms\n",
      "251:\tlearn: 0.2545290\ttotal: 483ms\tremaining: 92.1ms\n",
      "252:\tlearn: 0.2541272\ttotal: 485ms\tremaining: 90.2ms\n",
      "253:\tlearn: 0.2525612\ttotal: 488ms\tremaining: 88.3ms\n",
      "254:\tlearn: 0.2521989\ttotal: 490ms\tremaining: 86.4ms\n",
      "255:\tlearn: 0.2517572\ttotal: 492ms\tremaining: 84.5ms\n",
      "256:\tlearn: 0.2515952\ttotal: 494ms\tremaining: 82.6ms\n",
      "257:\tlearn: 0.2514307\ttotal: 496ms\tremaining: 80.7ms\n",
      "258:\tlearn: 0.2509742\ttotal: 498ms\tremaining: 78.8ms\n",
      "259:\tlearn: 0.2506860\ttotal: 500ms\tremaining: 76.9ms\n",
      "260:\tlearn: 0.2504957\ttotal: 502ms\tremaining: 75ms\n",
      "261:\tlearn: 0.2500729\ttotal: 504ms\tremaining: 73.1ms\n",
      "262:\tlearn: 0.2498829\ttotal: 506ms\tremaining: 71.1ms\n",
      "263:\tlearn: 0.2495885\ttotal: 508ms\tremaining: 69.3ms\n",
      "264:\tlearn: 0.2491647\ttotal: 510ms\tremaining: 67.3ms\n",
      "265:\tlearn: 0.2491026\ttotal: 511ms\tremaining: 65.3ms\n",
      "266:\tlearn: 0.2487057\ttotal: 513ms\tremaining: 63.4ms\n",
      "267:\tlearn: 0.2479544\ttotal: 515ms\tremaining: 61.5ms\n",
      "268:\tlearn: 0.2479392\ttotal: 515ms\tremaining: 59.4ms\n",
      "269:\tlearn: 0.2477180\ttotal: 517ms\tremaining: 57.5ms\n",
      "270:\tlearn: 0.2472565\ttotal: 520ms\tremaining: 55.6ms\n",
      "271:\tlearn: 0.2468224\ttotal: 522ms\tremaining: 53.7ms\n",
      "272:\tlearn: 0.2463928\ttotal: 524ms\tremaining: 51.8ms\n",
      "273:\tlearn: 0.2462559\ttotal: 526ms\tremaining: 49.9ms\n",
      "274:\tlearn: 0.2455348\ttotal: 528ms\tremaining: 48ms\n",
      "275:\tlearn: 0.2451552\ttotal: 530ms\tremaining: 46.1ms\n",
      "276:\tlearn: 0.2449777\ttotal: 532ms\tremaining: 44.2ms\n",
      "277:\tlearn: 0.2446884\ttotal: 534ms\tremaining: 42.3ms\n",
      "278:\tlearn: 0.2442318\ttotal: 536ms\tremaining: 40.3ms\n",
      "279:\tlearn: 0.2439186\ttotal: 538ms\tremaining: 38.4ms\n",
      "280:\tlearn: 0.2436106\ttotal: 540ms\tremaining: 36.5ms\n",
      "281:\tlearn: 0.2434099\ttotal: 542ms\tremaining: 34.6ms\n",
      "282:\tlearn: 0.2432559\ttotal: 544ms\tremaining: 32.7ms\n",
      "283:\tlearn: 0.2429828\ttotal: 546ms\tremaining: 30.8ms\n",
      "284:\tlearn: 0.2421455\ttotal: 548ms\tremaining: 28.9ms\n",
      "285:\tlearn: 0.2418231\ttotal: 551ms\tremaining: 27ms\n",
      "286:\tlearn: 0.2417401\ttotal: 553ms\tremaining: 25ms\n",
      "287:\tlearn: 0.2412838\ttotal: 555ms\tremaining: 23.1ms\n",
      "288:\tlearn: 0.2403691\ttotal: 557ms\tremaining: 21.2ms\n",
      "289:\tlearn: 0.2402637\ttotal: 558ms\tremaining: 19.2ms\n",
      "290:\tlearn: 0.2398234\ttotal: 560ms\tremaining: 17.3ms\n",
      "291:\tlearn: 0.2396521\ttotal: 562ms\tremaining: 15.4ms\n",
      "292:\tlearn: 0.2391017\ttotal: 564ms\tremaining: 13.5ms\n",
      "293:\tlearn: 0.2383553\ttotal: 566ms\tremaining: 11.6ms\n",
      "294:\tlearn: 0.2377191\ttotal: 569ms\tremaining: 9.64ms\n",
      "295:\tlearn: 0.2374919\ttotal: 571ms\tremaining: 7.71ms\n",
      "296:\tlearn: 0.2371845\ttotal: 573ms\tremaining: 5.78ms\n",
      "297:\tlearn: 0.2370660\ttotal: 575ms\tremaining: 3.85ms\n",
      "298:\tlearn: 0.2367818\ttotal: 577ms\tremaining: 1.93ms\n",
      "299:\tlearn: 0.2364735\ttotal: 578ms\tremaining: 0us\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<catboost.core.CatBoostClassifier at 0x18bfde28df0>"
      ]
     },
     "execution_count": 196,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xgb_clf.fit(x_train,y_train)\n",
    "lgb_clf.fit(x_train,y_train)\n",
    "cat_clf.fit(x_train,y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 198,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.8268156424581006, 0.8156424581005587, 0.8268156424581006)"
      ]
     },
     "execution_count": 198,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xgb_clf.score(x_test,y_test),lgb_clf.score(x_test,y_test),cat_clf.score(x_test,y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['cat_clf.pkl']"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "joblib.dump(xgb_clf,\"xgb_clf.pkl\")\n",
    "joblib.dump(lgb_clf,\"lgb_clf.pkl\")\n",
    "joblib.dump(cat_clf,\"cat_clf.pkl\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 集成模型运用与生成提交文件功能的函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 200,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_submission_file(test_file,model_file):\n",
    "    ''' \n",
    "    加载训练好的模型，并生成提交文件\n",
    "    parameters：\n",
    "    test_file:测试集文件路径\n",
    "    model_file：模型文件路径\n",
    "    '''\n",
    "    #对测试数据进行预处理\n",
    "    data=data_clean(test_file)\n",
    "    #加载模型参数\n",
    "    model=joblib.load(model_file)\n",
    "    #生成提交文件\n",
    "    submission = pd.DataFrame(\n",
    "    {\n",
    "        \"PassengerId\": pd.read_csv(test_file)['PassengerId'],\n",
    "        \"Survived\": model.predict(data)\n",
    "    })\n",
    "    submission.to_csv('submission_'+model_file.replace('pkl','csv'), index=False)   \n",
    "    #字符串似乎没有“——”这个操作，这里使用replace函数进行自动化处理\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "metadata": {},
   "outputs": [],
   "source": [
    "generate_submission_file('data/test.csv','cat_clf.pkl')\n",
    "generate_submission_file('data/test.csv','xgb_clf.pkl')\n",
    "generate_submission_file('data/test.csv','lgb_clf.pkl')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.5 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "56316dc990450f2e68fc9b6ef9f2f6c950193668e294abbff0bb7cf1419f9ab8"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
